@/*
    id : input框id
    name : input框名称
    value : value
    fields : [{ 
    			title:"",
    			type:"",// input、select、
    			field:"",
    			width:"",
    			map:{}//select的map
    		}]
@*/
@/*
示例：
	\@var _fields = [{ 
	\@	title:"参数",
	\@	field:"code"
	\@},{ 
	\@	title:"参数文本",
	\@	field:"text"
	\@},{ 
	\@	title:"默认值",
	\@	field:"value"
	\@},{ 
	\@	title:"隐藏参数",
	\@	field:"hidden",
	\@	type:"select",
	\@	map:{'0':"否",'1':"是"}
	\@}];
	<#ParmsEdit id="rpParams" name="参数" fields="${_fields}"/>
	
	${id}_editor.val()
	${id}_editor.set(value)
@*/
<div class="form-group">
	@if(!isEmpty(name)){
	<label class="lab">${name}</label>
	@}
    <div class="ele ${isEmpty(name)?'ele-fit':''}">
		<table class="table table-bordered">
			<thead>
				<tr>
					@for(ele in fields){
						@if(!isEmpty(ele.width)){
							<th width="${ele.width}">${ele.title}</th>
						@}else{
							<th>${ele.title}</th>
						@}
					@}
					<th width="60px">
						<button type="button" class="btn btn-success btn-xs " onclick="${id}_editor.addItem()">
						    <i class="fa fa-plus"></i>
						</button>
					</th>
				</tr>
			</thead>
			<tbody id="${id}_tbody">
			</tbody>
		</table>
	</div>
</div>
<input type="hidden" id="${id}" name="${id}" value="${value!}">
<script type="text/template" id="${id}_itemTemplate">
	<tr>
		@for(ele in fields){
			@if(!isEmpty(ele.type)){
				@if(ele.type=="select"){
					<td><select class="textbox" name="${id}_${ele.field}">
						@for(item in ele.map){
							<option value="${item.key}">${item.value}</option>
						@}
			        </select></td>
				@}else if(ele.type=="checkbox"){
					<td>
						<input type="checkbox" name="${id}_${ele.field}"/>
					</td>
				@}else{
					<td><input class="textbox" type="text" name="${id}_${ele.field}"/></td>
				@}
			@}else{
				<td><input class="textbox" type="text" name="${id}_${ele.field}"/></td>
			@}
		@}
		<td>
			<button type="button" class="btn btn-danger" onclick="${id}_editor.delItem(this)">
			    <i class="fa fa-remove"></i>
			</button>
		</td>
	</tr>
</script>
<script>
var ${id}_editor={}
${id}_editor.addItem = function(){
    $("#${id}_tbody").append($("#${id}_itemTemplate").html());
}
${id}_editor.delItem = function(obj){
    $(obj).parent().parent().remove();
}
${id}_editor.val = function(){
	var _ja = [];
    $("#${id}_tbody").find("tr").each(function(){
        var _jo = {};
		@for(ele in fields){
			@if(ele.type=="checkbox"){
				_jo["${ele.field}"]=$(this).find("[name='${id}_${ele.field}']").is(":checked");
			@}else{
				_jo["${ele.field}"]=$(this).find("[name='${id}_${ele.field}']").val();
			@}
		@}
        _ja.push(_jo);
    });
    return JSON.stringify(_ja).replace(/\"/g,"\'");  
}
${id}_editor.set = function(data){
	var _html = '';
	$.each(data,function(i,_jo){
		_html += '<tr>';
		@for(ele in fields){
			@if(!isEmpty(ele.type)){
				@if(ele.type=="select"){
					_html += '<td>';
					_html += '<select class="textbox" name="${id}_${ele.field}">';
					@for(item in ele.map){
						_html += '<option value="${item.key}" ' + (_jo['${ele.field}']=="${item.key}"?'selected = "selected"':'') + '>${item.value}</option>';
					@}
				    _html += '</select>';
					_html += '</td>';
				@}else if(ele.type=="checkbox"){
					_html += '<td>';
					_html += '<input type="checkbox" name="${id}_${ele.field}" ' +(_jo['${ele.field}']?'checked="checked"':'')+ '/>';
					_html += '</td>';
				@}else{
					_html += '<td><input class="textbox" type="text" name="${id}_${ele.field}" value="'+_jo['${ele.field}']+'"></td>';
				@}
			@}else{
				_html += '<td><input class="textbox" type="text" name="${id}_${ele.field}" value="'+_jo['${ele.field}']+'"></td>';
			@}
		@}
		_html += '	<td>';
		_html += '		<button type="button" class="btn btn-danger" onclick="${id}_editor.delItem(this)">';
		_html += '		    <i class="fa fa-remove"></i>';
		_html += '		</button>';
		_html += '	</td>';
		_html += '</tr>';
	});
	$("#${id}_tbody").html(_html);
}
@if(isNotEmpty(value)){
$().ready(function(){
	var _val = "${value}";
	var _ja = eval("("+_val+")");
	${id}_editor.set(_ja);
});
@}
</script>
@if(isNotEmpty(underline) && underline == 'true'){
    <div class="hr-line-dashed"></div>
@}


